; RestoreThreadContext(DWORD dwESP)

global RestoreThreadContext
extern VideoTextModePutString
RestoreThreadContext:
    ; push 7
    ; push .string
    ; call VideoTextModePutString
    ; add esp, 8
    mov esp, [esp + 4] ; 切换栈顶指针
    pop edi
    pop esi
    pop ebx
    pop ebp
    pop edx
    pop ecx
    pop eax
    pop gs
    pop fs
    pop es
    pop ds
    add esp, 8 ; 跳过中断向量号和错误码
    test dword [esp + 4], 0x11 ; 是否返回到内核态
    jnz .return
    add esp, 20
    push dword [esp - 12]
    push dword [esp - 12]
    push dword [esp - 12]
.return:
    push eax
    mov al, 0x20 ; 中断结束命令 EOI （End of Interupt）
    out 0x20, al ; Master Chip
    pop eax
    iret
.string: 
    db "Thread context switch occurs!", 0x0d, 0x0a, 0x00